#!/usr/bin/env python
#  This module is a series of classes which take the intermediate lexicon for each accent
#  And parses out of it Four Feature Dictionaries.  One for part-of-speech, one for pronunciation,
#  One for orthography, and one for word frequency.

import config import PATH_INTER_GAM


def singleton(klass):
    instances = {}
    def get_instance():
        if klass not in instances:
            instances[klass] = klass()
        return instances[klass]
    return get_instance


#  Class for General American
class _GAMinter(dict):
    """Four feature dicts for GAM"""

    dict_type = None

    
    def __init__(self, path_gam_inter=PATH_INTER_GAM):
        """Instantiate and populate this current dict."""

        super(dict, self).__init__()

        assert self.dict_type in ('pos', 'pron', 'ortho', 'freq',)

        with open(path_gam_inter) as f:
            for line in f.readlines():
                word, pron_num, pos, pron, ortho, freq = line.split(':')
                value = locals()[self.dict_type]
                try:
                    self[word].append(value)
                except KeyError:
                    self[word] = [value]

@singleton
class GamPOS(_GAMinter):
    dict_type = 'pos'

@singleton
class GamPron(_GAMinter):
    dict_type = 'pron'

@singleton
class GamOrtho(_GAMinter):
    dict_type = 'ortho'

@singleton
class GamFreq(_GAMinter):
    dict_type = 'freq'


